package com.ybear.ybhotrepair;

/**
 * 基础构建请求。允许自定义设置服务器的请求链接、接口、参数名称
 * 继承时：实现{@link #callSub()}方法返回设置好的构建请求。这样可以自行定义成员用于返回。
 *     private String url = "xxx";
 *     private String version = "1.0";
 *     @Override
 *     public BaseReqBuild callSub() {
 *         return new BaseReqBuild()
 *                 .setServerUrl( url )
 *                 .setParamVersion( version );
 *     }
 *
 * 实例时：通过get/set设置构建请求
 */
public class BaseReqBuild implements ISub {
    private int defStatusOfSuccess = 0;
    private String serverUrl = null;
    private String ctrlDexFile = "dexFile";
    private String apiQueryDex = "queryDex";
    private String apiCheckRepair = "checkRepair";

    private String paramToken = "token";
    private String paramVersion = "version";

    public BaseReqBuild() {
        BaseReqBuild build = callSub();
        if( build == null ) return;
        defStatusOfSuccess = build.defStatusOfSuccess;
        serverUrl = build.serverUrl;
        ctrlDexFile = build.ctrlDexFile;
        apiQueryDex = build.apiQueryDex;
        apiCheckRepair = build.apiCheckRepair;
        paramToken = build.paramToken;
        paramVersion = build.paramVersion;
    }

    @Override
    public String toString() {
        return "ReqBuild{" +
                "服务器链接:'" + serverUrl + '\'' +
                ", 正常返回时的默认状态:'" + defStatusOfSuccess + '\'' +
                ", Dex文件Controll接口:'" + ctrlDexFile + '\'' +
                ", 查询Dex文件API接口:'" + apiQueryDex + '\'' +
                ", 修复检查API接口:'" + apiCheckRepair + '\'' +
                ", Token参数名:'" + paramToken + '\'' +
                ", 补丁版本参数名:'" + paramVersion + '\'' +
                '}';
    }

    public int getDefStatusOfSuccess() {
        return defStatusOfSuccess;
    }
    public BaseReqBuild setDefStatusOfSuccess(int defStatusOfSuccess) {
        this.defStatusOfSuccess = defStatusOfSuccess;
        return this;
    }

    public String getServerUrl() {
        return serverUrl;
    }
    public BaseReqBuild setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
        return this;
    }

    public String apiQueryDex() { return ctrlDexFile + "/" + apiQueryDex; }
    public BaseReqBuild setApiQueryDex(String apiQueryDex) {
        this.apiQueryDex = apiQueryDex;
        return this;
    }

    public String apiCheckRepair() { return ctrlDexFile + "/" + apiCheckRepair; }
    public BaseReqBuild setApiCheckRepair(String apiCheckRepair) {
        this.apiCheckRepair = apiCheckRepair;
        return this;
    }

    public String getParamToken() {
        return paramToken;
    }
    public BaseReqBuild setParamToken(String paramToken) {
        this.paramToken = paramToken;
        return this;
    }

    public String getParamVersion() {
        return paramVersion;
    }
    public BaseReqBuild setParamVersion(String paramVersion) {
        this.paramVersion = paramVersion;
        return this;
    }

    /**
     * 回调代替的{@link BaseReqBuild}
     * @return  {@link BaseReqBuild}
     */
    @Override
    public BaseReqBuild callSub() { return null; }
}
interface ISub { BaseReqBuild callSub(); }